package com.test.spring;

import org.springframework.beans.BeansException;
import org.springframework.beans.PropertyValues;
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor;

import java.beans.PropertyDescriptor;

public class MyInstantiationAwareBeanPostProcessor implements InstantiationAwareBeanPostProcessor {

    //调用构造方法的时候执行的方法
    @Override
    public Object postProcessBeforeInstantiation(Class<?> aClass, String s) throws BeansException {
        System.out.println(" postProcessBeforeInstantiation " + " \n");
        return null;
    }
    //set方法，也就是依赖注入之前执行的方法
    @Override
    public boolean postProcessAfterInstantiation(Object o, String s) throws BeansException {
        System.out.println(" postProcessAfterInstantiation " + " \n");
        return true;
    }

    @Override
    public PropertyValues postProcessPropertyValues(PropertyValues propertyValues, PropertyDescriptor[] propertyDescriptors, Object o, String s) throws BeansException {
        System.out.println(" postProcessPropertyValues " + propertyValues + " \n");
        return propertyValues;
    }

    @Override
    public Object postProcessBeforeInitialization(Object o, String s) throws BeansException {
        System.out.println("1111 " + "\n");
        return o;
    }

    @Override
    public Object postProcessAfterInitialization(Object o, String s) throws BeansException {
        System.out.println("2222 " + "\n");
        return o;
    }
}
